package com.yfq.springframework.core.io;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author 姚凤桥
 * @date 2023/1/19 12:06
 * @description
 */
public class UrlResource implements Resource {
    private final URL url;

    public UrlResource(URL url) {
        this.url = url;
    }

    @Override
    public InputStream getInputStream() {
        try {
            URLConnection connection = url.openConnection();
            return connection.getInputStream();
        } catch (Exception e) {
            throw new RuntimeException("url读取异常：" + url);
        }
    }
}
